package com.qf.week1.day02;

import java.util.Random;
import java.util.Scanner;

public class GuessTel {
    public static void main(String[] args) {
        //1. 创建随机数对象
        Random random = new Random();
        //2. 调用对象的方法
        int i = random.nextInt(8000)+2000;
        System.out.println("实际价格是"+i);
        int guess;
        int count;
        System.out.println("请输入您猜测的价格(范围2000-10000元）");
        Scanner sc = new Scanner(System.in);
        guess = sc.nextInt();
        for(count = 5;count<=5;count--){
            if(count<5&&count>=0){
                if(guess != i){
                    if(count==0){
                        System.out.println("很遗憾，您没有机会猜了，无法获得此商品，竞猜结束");
                        break;
                    }else{
                        System.out.println("猜错了！还剩"+count+"次机会！请再次输入您猜测的价格(范围2000-10000元）");
                        guess = sc.nextInt();
                    }
                }else{

                    System.out.println("恭喜你,在还剩"+count +"次机会时，获得了此奖品");
                    break;

                }
            }else if(count ==-1){
                System.out.println("很遗憾，您没有机会猜了，无法获得此商品，竞猜结束");
                break;
            }
        }



    }
}
